package com.video.web.controller.system;

import java.util.List;

import com.video.system.service.IVideoEducationService;
import com.video.system.service.IVideoRoleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.video.common.annotation.Log;
import com.video.common.core.controller.BaseController;
import com.video.common.core.domain.AjaxResult;
import com.video.common.enums.BusinessType;
import com.video.system.domain.VideoUser;
import com.video.system.service.IVideoUserService;
import com.video.common.utils.poi.ExcelUtil;
import com.video.common.core.page.TableDataInfo;

/**
 * 用户Controller
 * 
 * @author lyh
 * @date 2021-07-31
 */
@RestController
@RequestMapping("/system/uuser")
public class VideoUserController extends BaseController
{
    @Autowired
    private IVideoUserService videoUserService;
    @Autowired
    private IVideoEducationService videoEducationService;
    @Autowired
    private IVideoRoleService videoRoleService;

    /**
     * 查询用户列表
     */
    @PreAuthorize("@ss.hasPermi('system:uuser:list')")
    @GetMapping("/list")
    public TableDataInfo list(VideoUser videoUser)
    {
        startPage();
        List<VideoUser> list = videoUserService.selectVideoUserList(videoUser);
        return getDataTable(list);
    }

    /**
     * 导出用户列表
     */
    @PreAuthorize("@ss.hasPermi('system:uuser:export')")
    @Log(title = "用户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(VideoUser videoUser)
    {
        List<VideoUser> list = videoUserService.selectVideoUserList(videoUser);
        ExcelUtil<VideoUser> util = new ExcelUtil<VideoUser>(VideoUser.class);
        return util.exportExcel(list, "用户数据");
    }

    /**
     * 获取用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:uuser:query')")
    @GetMapping(value = {"/","/{uId}"})
    @ApiOperation(value="获取用户详细信息",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = AjaxResult.class,
            notes="获取用户详细信息")
    public AjaxResult getInfo(@PathVariable(value = "uId",required = false) Integer uId)
    {
        AjaxResult ajax = AjaxResult.success(videoUserService.selectVideoUserById(uId));

        ajax.put("education",videoEducationService.selectCodeAndNameList());
        ajax.put("role",videoRoleService.selectCodeAndNameList());
        System.out.println("=======================>"+ajax);

        return ajax;
        //return AjaxResult.success(videoUserService.selectVideoUserById(uId));
    }

    /**
     * 新增用户
     */
    @PreAuthorize("@ss.hasPermi('system:uuser:add')")
    @Log(title = "用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VideoUser videoUser)
    {
        return toAjax(videoUserService.insertVideoUser(videoUser));
    }

    /**
     * 修改用户
     */
    @PreAuthorize("@ss.hasPermi('system:uuser:edit')")
    @Log(title = "用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VideoUser videoUser)
    {
        return toAjax(videoUserService.updateVideoUser(videoUser));
    }

    /**
     * 删除用户
     */
    @PreAuthorize("@ss.hasPermi('system:uuser:remove')")
    @Log(title = "用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uIds}")
    public AjaxResult remove(@PathVariable Integer[] uIds)
    {
        return toAjax(videoUserService.deleteVideoUserByIds(uIds));
    }
}
